<?php

namespace App\Commons\Domain\Module\Financial\Service;

use App\Commons\Domain\Core\DomainService;
use App\Commons\Domain\Module\Financial\Context\PaymentContext;
use App\Commons\Domain\Module\Financial\Contract\PaymentInterface;
use App\Commons\Domain\Module\Financial\Entity\PaymentEntity;
use App\Commons\Domain\Module\Financial\Model\Payment;

class PaymentService extends DomainService implements PaymentInterface
{
    public const CONTEXT = PaymentContext::class;

    /**
     * 创建收款方式
     * @param string $uid 用户uid
     * @param array $data 收款方式数据
     * @return mixed
     */
    public function storePayment(string $uid, array $data)
    {
        return app(PaymentEntity::class)->storePayment($uid,$data['type'],$data['name'],$data['bank_name']??'',$data['bank_branch']??'',$data['qr_code']??'',$data['account']??'');
    }

    /**
     * 修改收款方式
     * @param Payment $payment 收款方式模型
     * @param string $bank_name
     * @param string $bank_branch
     * @param string $qr_code
     * @param string $account
     * @return mixed
     */
    public function updatePayment(Payment $payment, string $bank_name, string $bank_branch, string $qr_code, string $account)
    {
        return app(PaymentEntity::class)->updatePayment($payment,$bank_name,$bank_branch,$qr_code,$account);
    }

    /**
     * 收款方式开关
     * @param Payment $payment 收款方式模型
     * @param int $status 状态：0-关闭，1-开启
     * @return mixed
     */
    public function switchPayment(Payment $payment, int $status)
    {
        return app(PaymentEntity::class)->switchPayment($payment,$status);

    }

    /**
     * 删除收款方式
     * @param int $paymentId
     * @return mixed
     */
    public function removePayment(int $paymentId)
    {
        return app(PaymentEntity::class)->remove($paymentId);
    }
}
